import { Cache } from "../../../../cache/Cache";
import { ESex } from "../../../../../../Message/Public/ESex";
import { ObjCreate } from "../../../common/ObjCreate";
import { Lv70NpcTalkFaceData } from "./Lv70NpcTalkFaceData";
import { DisplayUtil } from "../../../../../common/DisplayUtil";
type int = number;
//class Lv70NpcTalkTextParser
    
    export  class Lv70NpcTalkTextParser
    {
        

        public parse(arg1: string, arg2: int, arg3: int, arg4: int): Array<any>
        {
            var loc7=null;
            var loc8=0;
            var loc9=null;
            var loc10=null;
            var loc11=null;
            var loc12=null;
            var loc13=0;
            var loc14=0;
            var loc15=null;
            var loc16=null;
            var loc17=null;
            var loc18=null;
            var loc19=0;
            var loc20=null;
            var loc21=null;
            var loc22=null;
            var loc1=[];
            var loc2=arg1;
            while (loc2.indexOf(this.Label_UserName) >= 0) 
            {
                loc2 = loc2.replace(this.Label_UserName, "<font color=\'#00FE2A\'>" + Cache.instance.role.playerInfo.name + "</font>");
            }
            while (loc2.indexOf(this.Label_Choose) >= 0) 
            {
                loc7 = [];
                loc8 = loc2.indexOf(this.Label_Choose);
                loc7[0] = loc2.substr(0, loc8);
                loc7[1] = loc2.substr(loc8 + this.Label_Choose.length);
                loc9 = loc7[0];
                loc8 = (loc10 = loc7[1]).indexOf("}");
                loc11 = loc10.substr(0, loc8);
                loc12 = loc10.substr(loc8 + 1);
                loc7 = loc11.split(",");
                if (Cache.instance.role.entityInfo.sex != ESex._ESexMan) 
                {
                    loc10 = loc7[1] + loc12;
                }
                else 
                {
                    loc10 = loc7[0] + loc12;
                }
                loc2 = loc9 + loc10;
            }
            var loc3;
            var loc4;
            (loc4 = (loc3 = ObjCreate.createGTextField("", 0, 0, arg4, 400)).defaultTextFormat).leading = arg2;
            loc4.size = arg3;
            loc3.defaultTextFormat = loc4;
            loc3.width = arg4;
            loc3.multiline = true;
            loc3.wordWrap = true;
            var loc5=[];
            var loc6=0;
            while (loc6 < loc2.length) 
            {
                if (loc2.charAt(loc6) == "/") 
                {
                    loc13 = 1;
                    loc14 = -1;
                    loc15 = loc2.charAt(loc6 + 1);
                    loc16 = loc2.charAt(loc6 + 2);
                    if (this.isNum(loc15)) 
                    {
                        ++loc13;
                        loc14 = parseInt(loc15);
                        if (this.isNum(loc16)) 
                        {
                            ++loc13;
                            loc14 = loc14 * 10 + parseInt(loc16);
                        }
                    }
                    if (loc14 >= 0 && loc14 <= 71) 
                    {
                        loc17 = loc2.substr(0, loc6);
                        loc18 = loc2.substr(loc6 + loc13);
                        loc3.htmlText = loc17;
                        loc19 = loc3.numLines;
                        loc20 = loc3.getLineText((loc19 - 1));
                        loc21 = loc3.getLineMetrics((loc19 - 1));
                        (loc22 = new Lv70NpcTalkFaceData()).faceId = loc14;
                        loc22.faceX = DisplayUtil.getStringPixes(loc20, arg3) + 3;
                        loc22.faceY = (loc19 - 1) * (arg3 + arg2) - (22 - arg3) / 2 + 1;
                        loc5.push(loc22);
                        if (loc17 == null) 
                        {
                            loc2 = this.Label_Face;
                        }
                        else 
                        {
                            loc2 = loc17 + this.Label_Face;
                        }
                        if (loc18 != null) 
                        {
                            loc2 = loc2 + loc18;
                        }
                    }
                }
                ++loc6;
            }
            loc1.push(loc2);
            loc1.push(loc5);
            return loc1;
        }

        /* internal  */isNum(arg1: string): Boolean
        {
            if (arg1 < "0") 
            {
                return false;
            }
            if (arg1 > "9") 
            {
                return false;
            }
            return true;
        }

        public /* const */Label_UserName: string="{name}";

        public /* const */Label_Choose: string="{A,B}={";

        public /* const */Label_Face: string="   ";
    }
